define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	 $scope.form.fk_unit=params.fk_unit;
	 $scope.form.academic = params.academic;
	 $scope.form.semester = params.semester;
	 $scope.form.fk_class = params.fk_class;
	 $scope.form.week = params.week;
	httpService.post(app.urls.course_info_selectByClass,$scope.form,function(data){
		if("0000" === data.code){
			$scope.tables = data.data;
		}else{
			alert(data.msg);
		}
	});
	httpService.post(app.urls.course_time_selectByClass,$scope.form,function(data){
		if("0000" === data.code){
			$scope.dataList = data.data;
		}else{
			alert(data.msg);
		}
	});
	$scope.saveForm = function(){
		var course_tables=[];
		for (var i = 0; i < $scope.dataList.length; i++) {
			if($scope.dataList[i].course_table1){
				var course_table = {};
				for (var j = 0; j < $scope.tables.length; j++) {
					if($scope.dataList[i].course_table1 == $scope.tables[j].id){
						course_table.fk_user= $scope.tables[j].fk_user;
						course_table.day='1';
						course_table.fk_course_time= $scope.dataList[i].id;
						course_table.fk_course_info= $scope.dataList[i].course_table1;
						course_tables.push(course_table);
					}
				}
			}else {
				var course_table = {};
				course_table.day='1';
				course_table.fk_course_time= $scope.dataList[i].id;
				course_tables.push(course_table);
			}
			if($scope.dataList[i].course_table2){
				var course_table = {};
				for (var j = 0; j < $scope.tables.length; j++) {
					if($scope.dataList[i].course_table2 == $scope.tables[j].id){
						course_table.fk_user= $scope.tables[j].fk_user;
						course_table.day='2';
						course_table.fk_course_time= $scope.dataList[i].id;
						course_table.fk_course_info= $scope.dataList[i].course_table2;
						course_tables.push(course_table);
					}
				}
			}else {
				var course_table = {};
				course_table.day='2';
				course_table.fk_course_time= $scope.dataList[i].id;
				course_tables.push(course_table);
			}
			if($scope.dataList[i].course_table3){
				var course_table = {};
				for (var j = 0; j < $scope.tables.length; j++) {
					if($scope.dataList[i].course_table3 == $scope.tables[j].id){
						course_table.fk_user= $scope.tables[j].fk_user;
						course_table.day='3';
						course_table.fk_course_time= $scope.dataList[i].id;
						course_table.fk_course_info= $scope.dataList[i].course_table3;
						course_tables.push(course_table);
					}
				}
			}else {
				var course_table = {};
				course_table.day='3';
				course_table.fk_course_time= $scope.dataList[i].id;
				course_tables.push(course_table);
			}
			if($scope.dataList[i].course_table4){
				var course_table = {};
				for (var j = 0; j < $scope.tables.length; j++) {
					if($scope.dataList[i].course_table4 == $scope.tables[j].id){
						course_table.fk_user= $scope.tables[j].fk_user;
						course_table.day='4';
						course_table.fk_course_time= $scope.dataList[i].id;
						course_table.fk_course_info= $scope.dataList[i].course_table4;
						course_tables.push(course_table);
					}
				}
			}else {
				var course_table = {};
				course_table.day='4';
				course_table.fk_course_time= $scope.dataList[i].id;
				course_tables.push(course_table);
			}
			if($scope.dataList[i].course_table5){
				var course_table = {};
				for (var j = 0; j < $scope.tables.length; j++) {
					if($scope.dataList[i].course_table5 == $scope.tables[j].id){
						course_table.fk_user= $scope.tables[j].fk_user;
						course_table.day='5';
						course_table.fk_course_time= $scope.dataList[i].id;
						course_table.fk_course_info= $scope.dataList[i].course_table5;
						course_tables.push(course_table);
					}
				}
			}else {
				var course_table = {};
				course_table.day='5';
				course_table.fk_course_time= $scope.dataList[i].id;
				course_tables.push(course_table);
			}
		}
		httpService.post(app.urls.course_table_updateByClass,{"fk_unit":$scope.form.fk_unit,"academic":$scope.form.academic,"semester":$scope.form.semester,"week":$scope.form.week,"fk_class":$scope.form.fk_class,"course_table":JSON.stringify(course_tables)},function(data){
			if("0000" === data.code){
				eventBusService.publish("content.page.reload", data);
				eventBusService.publish("modal.page.close", {});
			}else{
				alert(data.msg);
			}
		});
	}
}}});